package com.yanqu.road.server.cmd.activity.liondance;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LionDanceProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.liondance.LionDanceModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.liondance.LionDanceMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_LION_DANCE_JUMP_ADD_ITEM, desc = "跳桩收集到道具")
public class LionDanceJumpItemAddCmd extends AbstractCommand {

    int type;
    int step;
    int time;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        LionDanceProto.LionDanceJumpItemAddReqMsg reqMsg = LionDanceProto.LionDanceJumpItemAddReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        step = reqMsg.getStep();
        time = reqMsg.getTime();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        if (!ActivityMgr.activityInTime(LionDanceMgr.getActivityInfo()) || LionDanceMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        if(type != 1 && type != 2){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        ret = player.getModule(LionDanceModule.class).jumpAddItem(type, step, time);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_LION_DANCE_JUMP_ADD_ITEM, LionDanceProto.LionDanceJumpItemAddRespMsg.newBuilder().setRet(ret).setType(type));
        }
    }
}
